package com.test13_访问控制权限;

/**
 * 多例设计模式
 * 只能有若干个实例化对象
 */
public class YootkDemo_03 {

    public static void main(String[] args) {
        Sex sexA = Sex.getInstance(Sex.MALE);
        Sex sexB = Sex.getInstance(Sex.MALE);
        Sex sexC = Sex.getInstance(Sex.FEMALE);
        Sex sexD = Sex.getInstance(Sex.FEMALE);
        System.out.println(sexA);
        System.out.println(sexB);
        System.out.println(sexC);
        System.out.println(sexD);
    }
}

class Sex {
    private String value;
    public static final int MALE = 0;
    public static final int FEMALE = 1;
    private static final Sex MALE_INSTANCE = new Sex("男");
    private static final Sex FEMALE_INSTANCE = new Sex("女");

    private Sex(String value) {
        this.value = value;
    }

    public static Sex getInstance(int choose) {
        switch (choose) {
            case MALE:
                return MALE_INSTANCE;
            case FEMALE:
                return FEMALE_INSTANCE;
            default:
                return null;
        }
    }

    @Override
    public String toString() {
        return super.toString() + ":" + this.value;
    }
}
